#include "CIntroState.h"
#include "SGD Wrappers/CSGD_TextureManager.h"
#include "SGD Wrappers/CSGD_Direct3D.h"
#include "SGD Wrappers/CSGD_DirectInput.h"
#include "CGame.h"
#include "CMainMenuState.h"

CIntroState::CIntroState()
{
	Type(MAIN);
	m_nImageOne = CSGD_TextureManager::GetInstance()->LoadTexture("resource/graphics/Ludicrum_Logo.png");
	m_nImageTwo = CSGD_TextureManager::GetInstance()->LoadTexture("resource/graphics/title.png");
	m_fTimer = 0;
	m_nModifier = 1;
	m_nMode = ENTER_LOGO;
}

CIntroState::~CIntroState()
{

}

CIntroState* CIntroState::GetInstance()
{
	static CIntroState instance;
	return &instance;
}

void CIntroState::Enter()
{
	m_fTimer = 0;
	m_nModifier = 1;
	m_nMode = ENTER_LOGO;
}

bool CIntroState::Input()
{
	if(CSGD_DirectInput::GetInstance()->KeyPressedEx(DIK_ESCAPE) || 
		CSGD_DirectInput::GetInstance()->KeyPressedEx(DIK_RETURN))
	{
		switch(m_nMode)
		{
		case ENTER_LOGO:
			{
				m_nMode+=2;
				m_fTimer = 0;
			}
			break;
		case EXIT_LOGO:
			{
				m_nMode++;
				m_fTimer = 0;
			}
			break;
		case ENTER_TITLE:
			CGame::GetInstance()->ChangeState(CMainMenuState::GetInstance());
			break;
		case EXIT_TITLE:
			CGame::GetInstance()->ChangeState(CMainMenuState::GetInstance());
			break;
		}
		return true;
	}
	return true;
}

void CIntroState::Update(float fDelta)
{
	m_fTimer += (m_nModifier*(fDelta*50));
	switch(m_nMode)
	{
	case ENTER_LOGO:
		{
			if(m_fTimer >= 255)
			{
				m_nMode++;
				m_nModifier *= -1;
			}
		}
		break;
	case EXIT_LOGO:
		{
			if(m_fTimer <= 0)
			{
				m_nMode++;
				m_nModifier *= -1;
				m_fTimer = 0;
			}
		}
		break;
	case ENTER_TITLE:
		{
			if(m_fTimer >= 255)
			{
				m_nMode++;
				m_nModifier *= -1;
			}
		}
		break;
	case EXIT_TITLE:
		{
			if(m_fTimer <= 0)
				CGame::GetInstance()->ChangeState(CMainMenuState::GetInstance());
		}
		break;
	}
}

void CIntroState::Render()
{
	CSGD_Direct3D::GetInstance()->Clear(255,255,255);
	switch(m_nMode)
	{
	case ENTER_LOGO:
		CSGD_TextureManager::GetInstance()->Draw(
			m_nImageOne, 144, 172, 1,1, 0, 0, 0, 0, 
			D3DCOLOR_ARGB((int)m_fTimer, 255,255,255));
		break;
	case EXIT_LOGO:
		CSGD_TextureManager::GetInstance()->Draw(
			m_nImageOne, 144, 172, 1,1, 0, 0, 0, 0, 
			D3DCOLOR_ARGB((int)m_fTimer, 255,255,255));
		break;
	case ENTER_TITLE:
		CSGD_TextureManager::GetInstance()->Draw(
			m_nImageTwo, 144, 172, 1,1, 0, 0, 0, 0, 
			D3DCOLOR_ARGB((int)m_fTimer, 255,255,255));
		break;
	case EXIT_TITLE:
		CSGD_TextureManager::GetInstance()->Draw(
			m_nImageTwo, 144, 172, 1,1, 0, 0, 0, 0, 
			D3DCOLOR_ARGB((int)m_fTimer, 255,255,255));
		break;
	}
}

void CIntroState::Exit()
{

}